<template>
	<view>
		<view class="cu-bar bg-white" style="padding-top: 100upx;display: flex;flex-direction: row;height: 180upx;">
			<view class="action" @tap="back">
				<text class="cuIcon-back text-gray" style="font-size: 40upx;margin-left: 5upx;"></text> 
			</view>
			<view class="text-bold" style="font-size: 40upx;margin-left: 80upx;">
			    回复
			</view>
            <view >
                <button type="primary" size="mini"   style="margin-right: 40upx;" @tap="fabu"  :disabled="fasong">发布</button>
            </view>
		</view>
        <view  style="margin-top: 20upx;margin-left: 30upx;font-size: 40upx;width: 690upx;">
            <textarea  v-model="message" auto-height :placeholder="name" cursor=4 placeholder-style="font-size:50upx;padding-left:40upx;padding-top:20upx"
             @input="shuru" @blur="shuchu" @confirm="fabu"
              selection-start=4  selection-end=30
             style="font-size: 40ux;font-weight: 600;padding-top:20upx"
             :auto-focus="true" 
             />
      </view>
        
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
                name:'',
                message:'',
                type:0,
                fasong:true,
                commenttype:0
			}
		},
		methods: {
			fabu(){
                var c = this;
                var {id,message} = c;
                
                console.log(c.type)
                console.log(c.commenttype)
                // 发布到鸡汤的
               if(c.type == 1) {
                   // 发布到自评论的
                  if(c.commenttype == 1) {
                      
                      
                      console.log('12020')
                      
                      
                     this.$api.test({
 url:"setgoals/SetConsultCommentOfComment",
                   data:{
                       id:id,
                       message:message
                   },
                   method:"POST"
                   // header:{
                   //     "Content-Type":"application/x-www-form-urlencoded"
                   // }
                     }).then((res) =>{
                           console.log(res.data);
                       
                       let {status} = res.data;
                       
                       if(status === 0){
                           
                       uni.navigateBack({
                           delta: 1
                       });
                        
                        
                       }
                     }) 
                      
             
                  }else{
   
                   
                   this.$api.test({
              url:"setgoals/SetConsultComment",
              data:{
                  id:id,
                  message:message
              },
              method:"POST"
              // header:{
              //     "Content-Type":"application/x-www-form-urlencoded"
              // }
                                  }).then((res) =>{
                                       console.log(res.data)
                                       if(res.data.status == 500){
                                            uni.showToast({
                                               title: '回复失败',
                                               duration: 2000,
                                               icon:"none",
                                               position:"center"
                                               
                                           });
                                           return;
                                       }                       
                                                          let {status} = res.data;
                                                                                
                                                                                if(status === 0){
                                                                                    
                                                                                 uni.navigateBack({
                                                                                     delta: 1
                                                                                 });
                                                                                }  
                                  })
                   
                   
                      
                  }
                   
                   
                    
                   
                   
                   
               //发布到 目标的
               }
               
               if(c.type ==  0)
               {
                   
                   if(c.commenttype == 1){
                       
                                          
                                       
                    this.$api.test({
                  url:"setgoals/SetMyPlanCommentOfComment",
                  data:{
                      id:id,
                      message:message
                  },
                  method:"POST"
                  // header:{
                  //     "Content-Type":"application/x-www-form-urlencoded"
                  // }
                                        }).then((res) =>{
                                           console.log(res.data)
                                                                                          
                                                                                         let {status} = res.data;
                                                                                                               
                                                                                                               if(status === 0){
                                                                                                                   
                                                                                                               uni.navigateBack({
                                               delta: 1
                                           });
                                                                                                               }
                                        })                   
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                       
                                            
                       
                   }else{
                       
                          
                           
                  
                  
              this.$api.test({
              url:"setgoals/SetMyPlanComment",
              data:{
                  id:id,
                  message:message
              },
              method:"POST"
              // header:{
              //     "Content-Type":"application/x-www-form-urlencoded"
              // }
                                    }).then((res) =>{
                                     console.log(res.data)
                                                                    
                                                                     let {status} = res.data;
                                                                                           
                                                                                           if(status === 0){
                                                                                               
                                                                           uni.navigateBack({
                                         delta: 1
                                     });
                                                                                           }
                                    })                   
                                       
                  
                       
                   }   
               }
                  
            },
            focus(){
                
            },
            shuru(){
                this.fasong = false;
                if(this.message === ''){
                     this.fasong = true;
                }
              } ,
              
              shuchu(){
                  console.log(this.message)
                  if(this.message === ''){
                this.fasong = true;      
              }
              },
              back(){
                             uni.navigateBack({
                      delta: 1
                  });  
              }
		},
        onLoad(option) {
            console.log(option.id)
            console.log(option.name)
            console.log(option.commenttype)
        let {id,name,type,commenttype}= option
        
        console.log(option.type)
            
            this.id = id;
            this.name ='   回复: '+name;
            this.type = type;
            this.commenttype = commenttype;
            
            
        }
	}
</script>

<style>
.fabu{
   margin-right: 30upx;
   height: 100%;
   width: 100upx;
}
</style>
